package com.qf.ts.platform.front.feign;

import com.qf.ts.platform.front.feign.impl.CacheServiceFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Set;

@FeignClient(value = "TS-REDIS",path = "/cache",fallback= CacheServiceFallback.class)
public interface CacheService {

    /**
     * 将参数转成json写出去
     */
    @PostMapping("/hmset/{key}")
    boolean hMSet(@PathVariable(value = "key") String key, @RequestBody Object value) throws Exception;

    @PostMapping("/hmset/{key}")
    boolean hMSet(@PathVariable(value = "key") String key, @RequestBody Map<Object, Object> values) throws Exception;

    @PostMapping("/delete/{key}")
    boolean deleteKey(@PathVariable(value = "key") String key) throws Exception;

    @PostMapping("/sadd/{key}/{member}")
    Long sAdd(@PathVariable(value = "key") String key, @PathVariable(value = "member") String member) throws Exception;

    @PostMapping("/sadds/{key}")
    Long sAdd(@PathVariable(value = "key") String key, @RequestParam("members") String[] members) throws Exception;

    @PostMapping("/sremove/{key}/{member}")
    Long sRemove(@PathVariable(value = "key") String key, @PathVariable(value = "member") String member) throws Exception;

    @PostMapping("/set/{key}/{value}/{expireTime}")
    boolean save2Redis(@PathVariable(value = "key") String key, @PathVariable(value = "value") String value, @PathVariable(value = "expireTime") long expireTime) throws Exception;

    @GetMapping("/get/{key}")
    String getFromRedis(@PathVariable(value = "key") String key) throws Exception;

    @PostMapping("/expire/{key}/{expireTime}")
    boolean expire(@PathVariable(value = "key") String key, @PathVariable(value = "expireTime") long expireTime) throws Exception;

    @GetMapping("/getid/{key}")
    Long getAutoIncrementId(@PathVariable(value = "key") String key) throws Exception;

    @GetMapping("/smembers/{key}")
    Set<Object> sMembers(@PathVariable(value = "key") String key) throws Exception;

    @PostMapping("/hset/{key}/{field}/{value}")
    boolean hSet(@PathVariable(value = "key") String key, @PathVariable(value = "field") String field, @PathVariable(value = "value") String value) throws Exception;

    @GetMapping("/hget/{key}/{field}")
    String hGet(@PathVariable(value = "key") String key, @PathVariable(value = "field") String field) throws Exception;

    @GetMapping("/hgetall/{key}")
    Map<Object, Object> hGetAll(@PathVariable(value = "key") String key) throws Exception;

    @GetMapping("/keys/{patten}")
    Set<String> findKeyByPartten(@PathVariable(value = "patten") String patten) throws Exception;

    @GetMapping("/increment/{key}/{delta}")
    Long getAutoIncrementId(@PathVariable(value = "key") String key, @PathVariable(value = "delta") long delta) throws Exception;

    @GetMapping("/hIncrementid/{key}/{field}/{delta}")
    Long hIncrementId(@PathVariable(value = "key") String key, @PathVariable(value = "field") String field, @PathVariable(value = "delta") long delta) throws Exception;

    @PostMapping("/setnx/{key}/{value}/{expireTime}")
    boolean setNx(@PathVariable(value = "key") String key, @PathVariable(value = "value") String value, @PathVariable(value = "expireTime") long expireTime) throws Exception;




}
